<?php

class Model_Listing_Maid extends Model_Listing implements Model_Listing_Interface
{
    protected static  $_collection = 'listing';

    const COUNTRY_HONGKONG    = 1;
    const COUNTRY_INDONESIA   = 2;
    const COUNTRY_MALAYSIA    = 3;
    const COUNTRY_MIDDLEEAST  = 4;
    const COUNTRY_PHILIPPINES = 5;
    const COUNTRY_SINGAPORE   = 6;
    const COUNTRY_TAIWAN      = 7;
    const COUNTRY_THAILAND    = 8;
    const COUNTRY_CHINA       = 9;

    

    protected static $_requirements = array(
     //   'em'  => array('Required', 'Validator:EmailAddress'), //Email
        'hc'  => array('Array'), //householdcleaning
        'lag' => array('Array'), //languages
        'et'  => array('Array'), //employmenttype
        'yoec'  => array('Array'), //yearsofexperience - country
    );

    protected $_category = array();

    public function __construct($data = array(), $config = array()) {
        static::$_transcript = array_merge(array(
            //Main attributes
            'dob'  => 'dateofbirth',
            'ed'  => 'education',
            'lag' => 'languages',                    //Should be multiple choice
            'na'  => 'nationality',
            're'  => 'religion',
            'ms'  => 'maritalstatus',
            'ge'  => 'gender',
            'as'  => 'availabletostart',             //Date
            'et'  => 'employmenttype',           
            'vs'  => 'visastatus',
            'rlj' => 'reasonleavingpreviousjob',
            'pe' => 'previous_employers',
            'cn'  => 'contact_number',
			
            //translation
            'rlj_en' => 'reasonleavingpreviousjob_en',
            'rlj_tc' => 'reasonleavingpreviousjob_tc',
            'pe_en' => 'previous_employers_en',
            'pe_tc' => 'previous_employers_tc',
            'spo_en' => 'specialities_en',
            'spo_tc' => 'specialities_tc',
            'cs_en' => 'description_en',
            'cs_tc' => 'description_tc',
			
            //Cooking Styles
            'slw' => 'skilllevelwestern',
            'slc' => 'skilllevelchinese',
            'spo' => 'specialities',

            //People Care and Nursing
            'yen' => 'yearsexperiencenewborn',
            'yec' => 'yearsexperiencechildren',
            'yed' => 'yearsexperiencedisable',
            'yee' => 'yearsexperienceelderly',

            //Household and Cleaning
            'hc' => 'householdcleaning',

            //Overseas Experience
            'yoec' => 'yoe_country',
            /*
            'hkye' => 'hongkongyearsexperience',
            'inye' => 'indonesiayearsexperience',
            'maye' => 'malaysiayearsexperience',
            'miye' => 'middleeastyearsexperience',
            'phye' => 'philippinesyearsexperience',
            'siye' => 'singaporeyearsexperience',
            'taye' => 'taiwanyearsexperience',
            'thye' => 'thailandyearsexperience',
            'chye' => 'chinayearsexperience',
            */
            
            //Optional
            'sr' => 'salary',
            'we' => 'weight',
            'he' => 'height',
            'pjl' => 'preferredjoblocation',
         ), static::$_transcript);
        parent::__construct($data, $config);
    }
    public static function getTranslationFormField()
    {
        $arr = array(
			'tl_en' => 'text',
			'rlj_en' => 'textarea',
			'pe_en' => 'textarea',
			'spo_en' => 'text',
			'cs_en' => 'textarea',
			
		);

		return $arr;
    }
    public function __get($name)
    {
        if ($name == 'age') {
            $dob        = $this->dob;
            if (is_object($dob)) {
                $dob = $dob->sec;
            } else {
                $dob = strtotime($dob);
            }
            $year_diff  = date('Y') - date('Y', $dob);
            $month_diff = date('m') - date('m', $dob);
            $day_diff   = date('d') - date('d', $dob);
            
            if ($month_diff < 0) {
                $year_diff--;
            }  elseif (($month_diff == 0) && ($day_diff < 0)) {
                $year_diff--;
            }
            return $year_diff;
        } elseif ($name == 'horoscope') {
            $dob        = $this->dob;
            if (is_object($dob)) {
                $dob = $dob->sec;
            } else {
                $dob = strtotime($dob);
            }  
            list($year,$month,$day)=explode("-",date('Y-m-d', $dob));
            if (($month == 1 && $day > 20) || ($month == 2 && $day < 20)) {
                  return 'Aquarius';
             } else if(($month == 2 && $day > 18 ) || ($month == 3 && $day < 21)) {
                  return 'Pisces';
             } else if(($month == 3 && $day > 20)||($month == 4 && $day < 21)) {
                  return 'Aries';
             } else if(($month == 4 && $day > 20)||($month == 5 && $day < 22)) {
                  return 'Taurus';
             } else if(($month == 5 && $day > 21)||($month == 6 && $day < 22)) {
                  return 'Gemini';
             } else if(($month == 6 && $day > 21)||($month == 7 && $day < 24)) {
                  return 'Cancer';
             } else if(($month == 7 && $day > 23)||($month == 8 && $day < 24)) {
                  return 'Leo';
             } else if(($month == 8 && $day > 23)||($month == 9 && $day < 24)) {
                  return 'Virgo';
             } else if(($month == 9 && $day > 23)||($month == 10 && $day < 24)) {
                  return 'Libra';
             } else if(($month == 10 && $day > 23)||($month == 11 && $day < 23)) {
                  return 'Scorpio';
             } else if(($month == 11 && $day > 22)||($month == 12 && $day < 23)) {
                  return 'Sagittarius';
             } else if(($month == 12 && $day > 22)||($month == 1 && $day < 21)) {
                  return 'Capricorn';
             }
        } else {
            return parent::__get($name);
        }
    }
    

    public function postAnAddForm($options = array()) {
        $options = array_merge($options, array('category' => $this->category));
        return new Listing_Form_PostAnAddMaidForm($options);
    }

    public function getAdDetailPartialName()
    {
        return 'customization/maid.phtml';
    }

    public function getAdPreviewPartialName()
    {
        return $this->getAdDetailPartialName();
    }


    public static function getSearchResultPartialName()
    {
        return 'maids';
    }
    
    public static function getRefineSearchForm()
    {
        return new Search_Form_MaidRefineForm();
    }

    public static function processRefineSearchForm($page, $per_page, $sort, &$query, &$fields, &$additionalParameters)
    {
         $results = false;
        $fields  = array('description', 'title', 'area_l2_name', 'area_l1_name', 'street');
        $values  = array();
        $additionalParameters = array();
 
        $search_terms = self::getSearchTextTerms();
        
        $exact_search_terms = self::getExactSeachTerms();
        
        $q      = '';
        $qq     = !empty($_GET['keyword']) ? $_GET['keyword'] : '';
        $to_add = ' ';
        $get    = $_GET;
        
        //add the username
        if (!empty($get['keyword'])) {
            //$q = '(username_lower:"'.$get['keyword'].'"^50.0) ';
        }

        if (!empty($get['keyword'])) {
            if (!empty($exact_search_terms)) {
                foreach($exact_search_terms as $name => $val) {
                    foreach($val as $k => $v) {
                        if (preg_match('#('.$v.')#i', $get['keyword'], $match)) {
                            //var_dump($match, $v, $get['keyword'], str_ireplace( $v, '', $get['keyword']));
                            $get['keyword'] = str_ireplace( $v, '', $get['keyword']);
                            $q .= $to_add.str_replace('_name', '', $name) .':'.$k.'^5.0 ';
                            $to_add = ' OR ';
                        }
                    }
                }
                if (!empty($q) && !empty($tmp)) {
                    $q = ' OR ('.$tmp.') ';
                }
            }

            $pattern = '#(?<=([0-9]))\s+bedroom[s]?#iu';
            if (preg_match($pattern, strtolower($get['keyword']), $match)) {
                $qq = str_ireplace($match[1].$match[0], '"'.$match[1].$match[0].'"', $qq);
                $get['keyword'] = str_ireplace($match[1].$match[0], '', $get['keyword']);
                $tmp = ' bedroom:'.trim($match[1]).'^9.0 ';
                if (!empty($q)) {
                    $q .= ' OR ('.$tmp.') ';
                } else {
                    $q = $tmp;
                }
            }

            $to_add = ' ';

            //remove quoted words and add them to q
            $bak = $get['keyword'];


            $arr = preg_match_all('#\"(.*?)\"#i', $get['keyword'], $match);
            foreach ($match[1] as $v) {
                $q .= ' AND "'.$v.'"';
            }
            $get['keyword'] = preg_replace('#"(.*?)"#i', '', $get['keyword']);
            $qf = '';
            foreach($search_terms as $v => $weight) {
                $qf .= $v.'^'.$weight.' ';
            }

            if (!empty($qf)) {
                $additionalParameters['qf'] = $qf;
            }
            if (!empty($qq)) {
                $additionalParameters['qq']   = $qq;
            }  

            $get['keyword'] = trim($get['keyword']);
            if (!empty($get['keyword'])) {
                if (!empty($q)) {
                    $q.=' OR ';
                }
                $q .='(';
                foreach ($fields as $f) {
                    $list = explode(' ', trim($get['keyword']));
                    foreach($list as $vl) {
                        if (!empty($vl)) {
                            $q .= $to_add.''.$f.':'.$vl;
                            $to_add = ' OR ';
                        }
                    }
                }
                $q.=') ';
            }


            $q.= ' OR _query_:"{!dismax qf=$qf v=$qq}" ';
        }
        if (empty($_GET['keyword'])) {
            $q = '*:*';
        }
        
        $query = $q;
        $get['sort'] = empty($get['sort']) ? '' : $get['sort'];
        
        switch ($get['sort']) {
            case 'highest':
                $get['sort'] = 'highest';
                $sort = 'price desc';
                break;
            case 'lowest':
                $get['sort'] = 'lowest';
                $sort = 'is_free asc, price asc';
                break;
            case 'rel':
                $get['sort'] = 'rel';
                $sort = 'score desc';
                break;
            case 'recent':
                $get['sort'] = 'recent';
                $sort = 'posted_at desc';
                break;
            case 'status':
                $get['sort'] = 'status';
                $sort = 'status desc';
                break;
            default:
                if (!empty($get['keyword_car'])) {
                    $get['sort'] = 'rel';
                    $sort         = 'score desc';
                } else {
                    $get['sort'] = 'recent';
                    $sort         = 'posted_at desc';
                }
        }

        $additionalParameters['fl']   = '*,score';
        $additionalParameters['sort'] = $sort;



        //Parameters to refine search
        $fq         = '';
        $valuesplus = array();

        //Has Image
        if (!empty($_GET['key_search_tools']['has_image'])) {
            $valuesplus['has_image'] = true;
        }

        //Force only Maids
        $valuesplus['type_obj_s'] = 'Model_Listing_Maid';

        //Skill Level Western
        if (!empty($_GET['work']['key_search_tool_skilllevelwestern'])) {
            $valuesplus['skilllevelwestern'] = $_GET['work']['key_search_tool_skilllevelwestern'];
        }

        //Skill Level Chinese
        if (!empty($_GET['work']['key_search_tool_skilllevelchinese'])) {
            $valuesplus['skilllevelchinese'] = $_GET['work']['key_search_tool_skilllevelchinese'];
        }

        //Years of Experience Newborn
        if (isset($get['work-key_search_tool_yearsexperiencenewborn']) && isset($get['work-key_search_tool_yearsexperiencenewborn-1'])) {
            $test1 = false;$test2 = false;
            if ($get['work-key_search_tool_yearsexperiencenewborn-1'] == 10) {
                $get['work-key_search_tool_yearsexperiencenewborn-1'] = '*';
                $test1 = true;
            }
            if ($get['work-key_search_tool_yearsexperiencenewborn'] == 0) {
                $get['work-key_search_tool_yearsexperiencenewborn'] = '0';
                $test2 = true;
            }
            if (!$test1 || !$test2) {
                $valuesplus['yearsexperiencenewborn'] = '['.$get['work-key_search_tool_yearsexperiencenewborn'].' TO '.$get['work-key_search_tool_yearsexperiencenewborn-1'].']';
            }
        }

        //Years of Experience Children
        if (isset($get['work-key_search_tool_yearsexperiencechildren']) && isset($get['work-key_search_tool_yearsexperiencechildren-1'])) {
            $test1 = false;$test2 = false;
            if ($get['work-key_search_tool_yearsexperiencechildren-1'] == 10) {
                $get['work-key_search_tool_yearsexperiencechildren-1'] = '*';
                $test1 = true;
            }
            if ($get['work-key_search_tool_yearsexperiencechildren'] == 0) {
                $get['work-key_search_tool_yearsexperiencechildren'] = '0';
                $test2 = true;
            }
            if (!$test1 || !$test2) {
                $valuesplus['yearsexperiencechildren'] = '['.$get['work-key_search_tool_yearsexperiencechildren'].' TO '.$get['work-key_search_tool_yearsexperiencechildren-1'].']';
            }
        }

        //Years of Experience Disable
        if (isset($get['work-key_search_tool_yearsexperiencedisable']) && isset($get['work-key_search_tool_yearsexperiencedisable-1'])) {
            $test1 = false;$test2 = false;
            if ($get['work-key_search_tool_yearsexperiencedisable-1'] == 10) {
                $get['work-key_search_tool_yearsexperiencedisable-1'] = '*';
                $test1 = true;
            }
            if ($get['work-key_search_tool_yearsexperiencedisable'] == 0) {
                $get['work-key_search_tool_yearsexperiencedisable'] = '0';
                $test2 = true;
            }
            if (!$test1 || !$test2) {
                $valuesplus['yearsexperiencedisable'] = '['.$get['work-key_search_tool_yearsexperiencedisable'].' TO '.$get['work-key_search_tool_yearsexperiencedisable-1'].']';
            }
        }

        //Years of Experience Elderly
        if (isset($get['work-key_search_tool_yearsexperienceelderly']) && isset($get['work-key_search_tool_yearsexperienceelderly-1'])) {
            $test1 = false;$test2 = false;
            if ($get['work-key_search_tool_yearsexperienceelderly-1'] == 10) {
                $get['work-key_search_tool_yearsexperienceelderly-1'] = '*';
                $test1 = true;
            }
            if ($get['work-key_search_tool_yearsexperienceelderly'] == 0) {
                $get['work-key_search_tool_yearsexperienceelderly'] = '0';
                $test2 = true;
            }
            if (!$test1 || !$test2) {
                $valuesplus['yearsexperienceelderly'] = '['.$get['work-key_search_tool_yearsexperienceelderly'].' TO '.$get['work-key_search_tool_yearsexperienceelderly-1'].']';
            }
        }

        //Household and Cleaning
        if (!empty($_GET['work']['key_search_tool_householdcleaning'])) {
            $valuesplus['householdcleaning'] = $_GET['work']['key_search_tool_householdcleaning'];
        }
        
        //Years of Experience Hong Kong
        if (isset($get['work-key_search_tool_hongkongyearsexperience']) && isset($get['work-key_search_tool_hongkongyearsexperience-1'])) {
            $test1 = false;$test2 = false;
            if ($get['work-key_search_tool_hongkongyearsexperience-1'] == 10) {
                $get['work-key_search_tool_hongkongyearsexperience-1'] = '*';
                $test1 = true;
            }
            if ($get['work-key_search_tool_hongkongyearsexperience'] == 0) {
                $get['work-key_search_tool_hongkongyearsexperience'] = '0';
                $test2 = true;
            }
            if (!$test1 || !$test2) {
                $valuesplus['hongkongyearsexperience'] = '['.$get['work-key_search_tool_hongkongyearsexperience'].' TO '.$get['work-key_search_tool_hongkongyearsexperience-1'].']';
            }
        }

        //Years of Experience Indonesia
        if (isset($get['work-key_search_tool_indonesiayearsexperience']) && isset($get['work-key_search_tool_indonesiayearsexperience-1'])) {
            $test1 = false;$test2 = false;
            if ($get['work-key_search_tool_indonesiayearsexperience-1'] == 10) {
                $get['work-key_search_tool_indonesiayearsexperience-1'] = '*';
                $test1 = true;
            }
            if ($get['work-key_search_tool_indonesiayearsexperience'] == 0) {
                $get['work-key_search_tool_indonesiayearsexperience'] = '0';
                $test2 = true;
            }
            if (!$test1 || !$test2) {
                $valuesplus['indonesiayearsexperience'] = '['.$get['work-key_search_tool_indonesiayearsexperience'].' TO '.$get['work-key_search_tool_indonesiayearsexperience-1'].']';
            }
        }

        //Years of Experience Malaysia
        if (isset($get['work-key_search_tool_malaysiayearsexperience']) && isset($get['work-key_search_tool_malaysiayearsexperience-1'])) {
            $test1 = false;$test2 = false;
            if ($get['work-key_search_tool_malaysiayearsexperience-1'] == 10) {
                $get['work-key_search_tool_malaysiayearsexperience-1'] = '*';
                $test1 = true;
            }
            if ($get['work-key_search_tool_malaysiayearsexperience'] == 0) {
                $get['work-key_search_tool_malaysiayearsexperience'] = '0';
                $test2 = true;
            }
            if (!$test1 || !$test2) {
                $valuesplus['malaysiayearsexperience'] = '['.$get['work-key_search_tool_malaysiayearsexperience'].' TO '.$get['work-key_search_tool_malaysiayearsexperience-1'].']';
            }
        }

        //Years of Experience Middle East
        if (isset($get['work-key_search_tool_middleeastyearsexperience']) && isset($get['work-key_search_tool_middleeastyearsexperience-1'])) {
            $test1 = false;$test2 = false;
            if ($get['work-key_search_tool_middleeastyearsexperience-1'] == 10) {
                $get['work-key_search_tool_middleeastyearsexperience-1'] = '*';
                $test1 = true;
            }
            if ($get['work-key_search_tool_middleeastyearsexperience'] == 0) {
                $get['work-key_search_tool_middleeastyearsexperience'] = '0';
                $test2 = true;
            }
            if (!$test1 || !$test2) {
                $valuesplus['middleeastyearsexperience'] = '['.$get['work-key_search_tool_middleeastyearsexperience'].' TO '.$get['work-key_search_tool_middleeastyearsexperience-1'].']';
            }
        }

        //Years of Experience Philippines
        if (isset($get['work-key_search_tool_philippinesyearsexperience']) && isset($get['work-key_search_tool_philippinesyearsexperience-1'])) {
            $test1 = false;$test2 = false;
            if ($get['work-key_search_tool_philippinesyearsexperience-1'] == 10) {
                $get['work-key_search_tool_philippinesyearsexperience-1'] = '*';
                $test1 = true;
            }
            if ($get['work-key_search_tool_philippinesyearsexperience'] == 0) {
                $get['work-key_search_tool_philippinesyearsexperience'] = '0';
                $test2 = true;
            }
            if (!$test1 || !$test2) {
                $valuesplus['philippinesyearsexperience'] = '['.$get['work-key_search_tool_philippinesyearsexperience'].' TO '.$get['work-key_search_tool_philippinesyearsexperience-1'].']';
            }
        }

        //Years of Experience Singapore
        if (isset($get['work-key_search_tool_singaporeyearsexperience']) && isset($get['work-key_search_tool_singaporeyearsexperience-1'])) {
            $test1 = false;$test2 = false;
            if ($get['work-key_search_tool_singaporeyearsexperience-1'] == 10) {
                $get['work-key_search_tool_singaporeyearsexperience-1'] = '*';
                $test1 = true;
            }
            if ($get['work-key_search_tool_singaporeyearsexperience'] == 0) {
                $get['work-key_search_tool_singaporeyearsexperience'] = '0';
                $test2 = true;
            }
            if (!$test1 || !$test2) {
                $valuesplus['singaporeyearsexperience'] = '['.$get['work-key_search_tool_singaporeyearsexperience'].' TO '.$get['work-key_search_tool_singaporeyearsexperience-1'].']';
            }
        }

        //Years of Experience Taiwan
        if (isset($get['work-key_search_tool_taiwanyearsexperience']) && isset($get['work-key_search_tool_taiwanyearsexperience-1'])) {
            $test1 = false;$test2 = false;
            if ($get['work-key_search_tool_taiwanyearsexperience-1'] == 10) {
                $get['work-key_search_tool_taiwanyearsexperience-1'] = '*';
                $test1 = true;
            }
            if ($get['work-key_search_tool_taiwanyearsexperience'] == 0) {
                $get['work-key_search_tool_taiwanyearsexperience'] = '0';
                $test2 = true;
            }
            if (!$test1 || !$test2) {
                $valuesplus['taiwanyearsexperience'] = '['.$get['work-key_search_tool_taiwanyearsexperience'].' TO '.$get['work-key_search_tool_taiwanyearsexperience-1'].']';
            }
        }

        //Years of Experience Thailand
        if (isset($get['work-key_search_tool_thailandyearsexperience']) && isset($get['work-key_search_tool_thailandyearsexperience-1'])) {
            $test1 = false;$test2 = false;
            if ($get['work-key_search_tool_thailandyearsexperience-1'] == 10) {
                $get['work-key_search_tool_thailandyearsexperience-1'] = '*';
                $test1 = true;
            }
            if ($get['work-key_search_tool_thailandyearsexperience'] == 0) {
                $get['work-key_search_tool_thailandyearsexperience'] = '0';
                $test2 = true;
            }
            if (!$test1 || !$test2) {
                $valuesplus['thailandyearsexperience'] = '['.$get['work-key_search_tool_thailandyearsexperience'].' TO '.$get['work-key_search_tool_thailandyearsexperience-1'].']';
            }
        }

        //Years of Experience Thailand
        if (isset($get['work-key_search_tool_otheryearsexperience']) && isset($get['work-key_search_tool_otheryearsexperience-1'])) {
            $test1 = false;$test2 = false;
            if ($get['work-key_search_tool_otheryearsexperience-1'] == 10) {
                $get['work-key_search_tool_otheryearsexperience-1'] = '*';
                $test1 = true;
            }
            if ($get['work-key_search_tool_otheryearsexperience'] == 0) {
                $get['work-key_search_tool_otheryearsexperience'] = '0';
                $test2 = true;
            }
            if (!$test1 || !$test2) {
                $valuesplus['otheryearsexperience'] = '['.$get['work-key_search_tool_otheryearsexperience'].' TO '.$get['work-key_search_tool_otheryearsexperience-1'].']';
            }
        }

        //Education
        if (!empty($_GET['personal']['key_search_tool_education'])) {
            $valuesplus['education'] = $_GET['personal']['key_search_tool_education'];
        }

        //Languages
        if (!empty($_GET['personal']['key_search_tool_languages'])) {
            $valuesplus['languages'] = $_GET['personal']['key_search_tool_languages'];
        }

        //Marital Status
        if (!empty($_GET['personal']['key_search_tool_maritalstatus'])) {
            $valuesplus['maritalstatus'] = $_GET['personal']['key_search_tool_maritalstatus'];
        }

        //Nationality
        if (!empty($_GET['personal']['key_search_tool_nationality'])) {
            $valuesplus['nationality'] = $_GET['personal']['key_search_tool_nationality'];
        }

        //Gender
        if (!empty($_GET['personal']['key_search_tool_gender'])) {
            $valuesplus['gender'] = $_GET['personal']['key_search_tool_gender'];
        }

        //Religion
        if (!empty($_GET['personal']['key_search_tool_religion'])) {
            $valuesplus['religion'] = $_GET['personal']['key_search_tool_religion'];
        }

        //Chinese Zodiac
        if (!empty($_GET['personal']['key_search_tool_chinesezodiac'])) {
            $valuesplus['chinesezodiac'] = $_GET['personal']['key_search_tool_chinesezodiac'];
        }

        //Horoscope
        if (!empty($_GET['personal']['key_search_tool_horoscope'])) {
            $valuesplus['horoscope'] = $_GET['personal']['key_search_tool_horoscope'];
        }

        //Visa Status
        if (!empty($_GET['personal']['key_search_tool_visastatus'])) {
            $valuesplus['visastatus'] = $_GET['personal']['key_search_tool_visastatus'];
        }

        //Employment Type
        if (!empty($_GET['personal']['key_search_tool_employmenttype'])) {
            $valuesplus['employmenttype'] = $_GET['personal']['key_search_tool_employmenttype'];
        }

        //Age
        if (isset($get['personal-key_search_tool_age']) && isset($get['personal-key_search_tool_age-1'])) {
            $test1 = false;$test2 = false;
            if ($get['personal-key_search_tool_age-1'] == 50) {
                $get['personal-key_search_tool_age-1'] = '*';
                $test1 = true;
            }
            if ($get['personal-key_search_tool_age'] == 18) {
                $get['personal-key_search_tool_age'] = '18';
                $test2 = true;
            }
            if (!$test1 || !$test2) {
                $valuesplus['age'] = '['.$get['personal-key_search_tool_age'].' TO '.$get['personal-key_search_tool_age-1'].']';
            }
        }

        //Height
        if (isset($get['personal-key_search_tool_height']) && isset($get['personal-key_search_tool_height-1'])) {
            $test1 = false;$test2 = false;
            if ($get['personal-key_search_tool_height-1'] == 175) {
                $get['personal-key_search_tool_height-1'] = '*';
                $test1 = true;
            }
            if ($get['personal-key_search_tool_height'] == 135) {
                $get['personal-key_search_tool_height'] = '135';
                $test2 = true;
            }
            if (!$test1 || !$test2) {
                $valuesplus['height'] = '['.$get['personal-key_search_tool_height'].' TO '.$get['personal-key_search_tool_height-1'].']';
            }
        }

        //Weight
        if (isset($get['personal-key_search_tool_weight']) && isset($get['personal-key_search_tool_weight-1'])) {
            $test1 = false;$test2 = false;
            if ($get['personal-key_search_tool_weight-1'] == 65) {
                $get['personal-key_search_tool_weight-1'] = '*';
                $test1 = true;
            }
            if ($get['personal-key_search_tool_weight'] == 30) {
                $get['personal-key_search_tool_weight'] = '30';
                $test2 = true;
            }
            if (!$test1 || !$test2) {
                $valuesplus['weight'] = '['.$get['personal-key_search_tool_weight'].' TO '.$get['personal-key_search_tool_weight-1'].']';
            }
        }

        foreach($valuesplus as $k => $val) {
          $valuesplus[$k] = '+'.$k.':'.$val.' ';
        }

        if (!empty($valuesplus)) {
            $fq .= implode(' ', $valuesplus);
        }


        $category = '';


        if (!empty($category)) {
            $fq .= $category;
        }

        if (!empty($fq)) {
            $additionalParameters['fq'] = $fq;
        }
    }
    
    public static function getCookingStyle() 
    {
        return array(
            'slw' => 'Western',
            'slc' => 'chinese',
        );
    }


    
    
    public static function getEducation($id = null)
    {
        $res = array('' => 'All') + self::getEducationPostAd();
        
        if ($id !== null && !empty($res[$id])) {
            return $res[$id];
        }
        return $res;  
    }

    public static function getEducationPostAd()
    {
        return array(
            '' => 'Select',
            1 => 'Elementary',
            2 => 'Junior High',
            3 => 'Senior High',
            4 => 'College',
            5 => 'University',
            999 => 'Other'
        );
    }

    public static function getLanguages($id = null)
    {
        $res = array('' => 'All') + self::getLanguagesPostAd();
        
        if ($id !== null && !empty($res[$id])) {
            return $res[$id];
        }
        return $res;  
    }

    public static function getLanguagesPostAd()
    {
        return array(
            'cs' => 'Chinese - Cantonese',
            'cm' => 'Chinese - Mandarin',
            'en' => 'English',
            'fl' => 'Tagalog',
            'fr' => 'French',
            'de' => 'German',
            'id' => 'Bahasa',
            'it' => 'Italian',
            'jp' => 'Japanese',
            'kr' => 'Korean',
            'pt' => 'Portuguese',
            'es' => 'Spanish',
            'th' => 'Thai',
            'vt' => 'Vietnamese',
        );
    }

    public static function getNationality($id = null)
    {
        $res = array('' => 'All') + self::getNationalityPostAd();
        
        if ($id !== null && !empty($res[$id])) {
            return $res[$id];
        }
        return $res;  
    }

    public static function getNationalityPostAd()
    {
        return array('' => 'Please select a Nationality') + self::getLocationPostAd();
    }

    public static function getGender($id = null)
    {
        $res = array(
            1 => 'Male',
            2 => 'Female'
        );
        if ($id !== null && !empty($res[$id])) {
            return $res[$id];
        }
        return $res;        
    }
    
    public static function getGenderSearch($id = null)
    {
        $res =  array('' => 'All') + self::getGender();
        
        if ($id !== null && !empty($res[$id])) {
            return $res[$id];
        }
        return $res;        
    }    

    public static function getMaritalStatus($id = null)
    {
        $res = array('' => 'All') + self::getMaritalStatusPostAd();
        
        if ($id !== null && !empty($res[$id])) {
            return $res[$id];
        }
        return $res;
    }

    public static function getMaritalStatusPostAd()
    {
        return array(
            '' => 'Select',
            1 => 'Single',
            2 => 'Married',
            3 => 'Separated',
            4 => 'Divorced',
            5 => 'Widowed'
        );
    }

    public static function getReligion($id = null)
    {
        $res = array('' => 'All') + self::getReligionPostAd();
        
        if ($id !== null && !empty($res[$id])) {
            return $res[$id];
        }
        return $res;
    }

    public static function getReligionPostAd()
    {
        return array(
            '' => 'Select',
            1 => 'Buddhist',
            2 => 'Catholic',
            3 => 'Christian',
            4 => 'Hindu',
            5 => 'Muslim',
            6 => 'Atheist',
            999 => 'Other'
        );
    }

    public static function getVisastatus($id = null)
    {
        $res = array('' => 'All') + self::getVisastatusPostAd();
        
        if ($id !== null  && !empty($res[$id])) {
            return $res[$id];
        }
        
        return array_slice($res, 0, 5);
    }

    public static function getVisastatusPostAd()
    {
        $view = Zend_Registry::get('Zend_View');
        return array(
            '' => 'Select',
            1 => 'Work',
            2 => 'Student',
            3 => 'Dependent',
            4 => 'Permanent Resident',
            5 => 'Yes',
            6 => 'No'
        );
    }

    public static function getEmploymentType($id = null)
    {
        $res = array('' => 'All') + self::getEmploymentTypePostAd();
        
        if ($id !== null && !empty($res[$id])) {
            return $res[$id];
        }
        return $res;
    }


    public static function getEmploymentTypePostAd()
    {
        return array(
            1 => 'Full-time',
            2 => 'Part-time',
        );
    }    
    
    public static function getSkillLevel($id = null)
    {
        $res = array('' => 'All') + self::getSkillLevelPostAd();
        
        if ($id !== null && !empty($res[$id])) {
            return $res[$id];
        }
        return $res;
    }

    public static function getSkillLevelPostAd()
    {
        return array(
            '' => 'Select',
            1 => 'Beginner',
            2 => 'Intermediate',
            3 => 'Advanced'
        );
    }

    public static function getPeopleCareNursing()
    {
        $view = Zend_Registry::get('Zend_View');
        return array(
            '' => 'All',
            1 => 'Newborn Experience',
            2 => 'Children Experience',
            3 => 'Disabled Experience',
            4 => 'Elderly Experience'
        );
    }
    
    
    public static function getPeopleCareNursingSearch() 
    {
        return array(
            'yen' => 'Newborn',
            'yec' => 'children',
            'yed' => 'Disable',
            'yee' => 'Elderly',
        );
    }    

    public static function getYearExperience($id = null)
    {
        $res = array('' => 'All') + self::getYearExperiencePostAd();
        
        if ($id !== null && !empty($res[$id])) {
            return $res[$id];
        }
        return $res;
    }

    public static function getYearExperiencePostAd()
    {
        return array(
            '' => 'Select',
            0 => '0',
            '1' => '1',
            '2' => '2',
            '3' => '3',
            '4' => '4',
            '5' => '5',
            '6' => '6',
            '7' => '7',
            '8' => '8',
            '9' => '9',
            '[10 TO *]' => '10 or above'
        );
    }

    public static function getHouseholdCleaning($id = null)
    {
        $res = array('' => 'All') + self::getHouseholdCleaningPostAd();
        
        if ($id !== null && !empty($res[$id])) {
            return $res[$id];
        }
        return $res;
    }

    public static function getHouseholdCleaningPostAd()
    {
        return array(
            1 => 'Gardening',
            2 => 'Pet Care',
            3 => 'Car Washing',
            4 => 'Washing and Ironing',
            5 => 'House Cleaning'
        );
    }

    public static function getLocation($id = null)
    {
        $res = array('' => 'All') + self::getLocationPostAd();
        
        if ($id !== null && !empty($res[$id])) {
            return $res[$id];
        }
        return $res;
    }

    public static function getLocationPostAd()
    {
        /*
        return array(
            '' => 'Select',
            self::COUNTRY_HONGKONG => 'Hong Kong',
            self::COUNTRY_CHINA => 'Mainland China',
            self::COUNTRY_INDONESIA => 'Indonesia',
            self::COUNTRY_MIDDLEEAST => 'Malaysia',
            self::COUNTRY_MIDDLEEAST => 'Middle East',
            self::COUNTRY_PHILIPPINES => 'Philippines',
            self::COUNTRY_SINGAPORE => 'Singapore',
            self::COUNTRY_TAIWAN => 'Taiwan',
            self::COUNTRY_THAILAND => 'Thailand',
        );
        */
        return array( 
            '' =>    'Please select a country', 
            'HK' => 'Hong Kong',  
            'CN' => 'China', 
            'ID' => 'Indonesia',  
            'MY' => 'Malaysia', 
            'PH' => 'Philippines', 
            'SG' => 'Singapore',  
            'TW' => 'Taiwan', 
            'TH' => 'Thailand', 
            '-'  => '------------------------------------------',
            'AF' =>    'Afganistan', 
            'AL' =>    'Albania', 
            'DZ' =>    'Algeria', 
            'AS' => 'American Samoa', 
            'AD' => 'Andorra',  
            'AO' => 'Angola', 
            'AI' => 'Anguilla', 
            'AQ' => 'Antarctica', 
            'AG' => 'Antigua and Barbuda',  
            'AR' => 'Argentina',  
            'AM' => 'Armenia',  
            'AW' => 'Aruba',  
            'AU' => 'Australia',  
            'AT' => 'Austria',  
            'AZ' => 'Azerbaijan', 
            'BS' => 'Bahamas',  
            'BH' => 'Bahrain',  
            'BD' => 'Bangladesh', 
            'BB' => 'Barbados', 
            'BY' => 'Belarus',  
            'BE' => 'Belgium',  
            'BZ' => 'Belize', 
            'BJ' => 'Benin',  
            'BM' => 'Bermuda',  
            'BT' => 'Bhutan', 
            'BO' => 'Bolivia',  
            'BA' => 'Bosnia and Herzegowina', 
            'BW' => 'Botswana', 
            'BV' => 'Bouvet Island',  
            'BR' => 'Brazil', 
            'IO' => 'British Indian Ocean Territory', 
            'BN' => 'Brunei Darussalam',  
            'BG' => 'Bulgaria', 
            'BF' => 'Burkina Faso', 
            'BI' => 'Burundi',  
            'KH' => 'Cambodia', 
            'CM' => 'Cameroon', 
            'CA' => 'Canada', 
            'CV' => 'Cape Verde', 
            'KY' => 'Cayman Islands', 
            'CF' => 'Central African Republic', 
            'TD' => 'Chad', 
            'CL' => 'Chile',  
            
            'CX' => 'Christmas Island',     
            'CC' => 'Cocos (Keeling) Islands',  
            'CO' => 'Colombia', 
            'KM' => 'Comoros',  
            'CG' => 'Congo',  
            'CD' => 'Congo, the Democratic Republic of the',  
            'CK' => 'Cook Islands', 
            'CR' => 'Costa Rica', 
            'CI' => 'Cote d\'Ivoire',  
            'HR' => 'Croatia (Hrvatska)', 
            'CU' => 'Cuba', 
            'CY' => 'Cyprus', 
            'CZ' => 'Czech Republic', 
            'DK' => 'Denmark',  
            'DJ' => 'Djibouti', 
            'DM' => 'Dominica', 
            'DO' => 'Dominican Republic', 
            'TP' => 'East Timor', 
            'EC' => 'Ecuador',  
            'EG' => 'Egypt',  
            'SV' => 'El Salvador',  
            'GQ' => 'Equatorial Guinea',  
            'ER' => 'Eritrea',  
            'EE' => 'Estonia',  
            'ET' => 'Ethiopia', 
            'FK' => 'Falkland Islands (Malvinas)',  
            'FO' => 'Faroe Islands',  
            'FJ' => 'Fiji', 
            'FI' => 'Finland', 
            'FR' => 'France', 
            'FX' => 'France, Metropolitan', 
            'GF' => 'French Guiana',  
            'PF' => 'French Polynesia', 
            'TF' => 'French Southern Territories',  
            'GA' => 'Gabon',  
            'GM' => 'Gambia', 
            'GE' => 'Georgia',  
            'DE' => 'Germany',  
            'GH' => 'Ghana',  
            'GI' => 'Gibraltar',  
            'GR' => 'Greece', 
            'GL' => 'Greenland',  
            'GD' => 'Grenada',  
            'GP' => 'Guadeloupe', 
            'GU' => 'Guam', 
            'GT' => 'Guatemala',  
            'GN' => 'Guinea', 
            'GW' => 'Guinea-Bissau',  
            'GY' => 'Guyana', 
            'HT' => 'Haiti',  
            'HM' => 'Heard and Mc Donald Islands',  
            'VA' => 'Holy See (Vatican City State)',  
            'HN' => 'Honduras', 
            
            'HU' => 'Hungary',  
            'IS' => 'Iceland',  
            'IN' => 'India',  
            
            'IR' => 'Iran (Islamic Republic of)', 
            'IQ' => 'Iraq', 
            'IE' => 'Ireland',  
            'IL' => 'Israel', 
            'IT' => 'Italy',  
            'JM' => 'Jamaica',  
            'JP' => 'Japan', 
            'JO' => 'Jordan', 
            'KZ' => 'Kazakhstan', 
            'KE' => 'Kenya',  
            'KI' => 'Kiribati', 
            'KP' => 'Korea, Democratic People\'s Republic of', 
            'KR' => 'Korea, Republic of', 
            'KW' => 'Kuwait', 
            'KG' => 'Kyrgyzstan', 
            'LA' => 'Lao People\'s Democratic Republic', 
            'LV' => 'Latvia', 
            'LB' => 'Lebanon', 
            'LS' => 'Lesotho',  
            'LR' => 'Liberia',  
            'LY' => 'Libyan Arab Jamahiriya', 
            'LI' => 'Liechtenstein',  
            'LT' => 'Lithuania', 
            'LU' => 'Luxembourg', 
            'MO' => 'Macau',  
            'MK' => 'Macedonia, The Former Yugoslav Republic of', 
            'MG' => 'Madagascar', 
            'MW' => 'Malawi', 
            
            'MV' => 'Maldives', 
            'ML' => 'Mali', 
            'MT' => 'Malta', 
            'MH' => 'Marshall Islands', 
            'MQ' => 'Martinique', 
            'MR' => 'Mauritania', 
            'MU' => 'Mauritius', 
            'YT' => 'Mayotte',  
            'MX' => 'Mexico', 
            'FM' => 'Micronesia, Federated States of', 
            'MD' => 'Moldova, Republic of', 
            'MC' => 'Monaco', 
            'MN' => 'Mongolia', 
            'MS' => 'Montserrat', 
            'MA' => 'Morocco', 
            'MZ' => 'Mozambique', 
            'MM' => 'Myanmar', 
            'NA' => 'Namibia', 
            'NR' => 'Nauru',  
            'NP' => 'Nepal',  
            'NL' => 'Netherlands', 
            'AN' => 'Netherlands Antilles', 
            'NC' => 'New Caledonia', 
            'NZ' => 'New Zealand',  
            'NI' => 'Nicaragua',  
            'NE' => 'Niger',  
            'NG' => 'Nigeria',  
            'NU' => 'Niue', 
            'NF' => 'Norfolk Island', 
            'MP' => 'Northern Mariana Islands', 
            'NO' => 'Norway', 
            'OM' => 'Oman', 
            'PK' => 'Pakistan', 
            'PW' => 'Palau', 
            'PA' => 'Panama', 
            'PG' => 'Papua New Guinea', 
            'PY' => 'Paraguay', 
            'PE' => 'Peru', 
            
            'PN' => 'Pitcairn', 
            'PL' => 'Poland', 
            'PT' => 'Portugal', 
            'PR' => 'Puerto Rico', 
            'QA' => 'Qatar', 
            'RE' => 'Reunion', 
            'RO' => 'Romania', 
            'RU' => 'Russian Federation', 
            'RW' => 'Rwanda', 
            'KN' => 'Saint Kitts and Nevis',  
            'LC' => 'Saint LUCIA',  
            'VC' => 'Saint Vincent and the Grenadines', 
            'WS' => 'Samoa',  
            'SM' => 'San Marino', 
            'ST' => 'Sao Tome and Principe', 
            'SA' => 'Saudi Arabia', 
            'SN' => 'Senegal', 
            'SC' => 'Seychelles', 
            'SL' => 'Sierra Leone', 
            
            'SK' => 'Slovakia (Slovak Republic)', 
            'SI' => 'Slovenia', 
            'SB' => 'Solomon Islands', 
            'SO' => 'Somalia',  
            'ZA' => 'South Africa', 
            'GS' => 'South Georgia and the South Sandwich Islands', 
            'ES' => 'Spain', 
            'LK' => 'Sri Lanka', 
            'SH' => 'St. Helena', 
            'PM' => 'St. Pierre and Miquelon',  
            'SD' => 'Sudan',  
            'SR' => 'Suriname', 
            'SJ' => 'Svalbard and Jan Mayen Islands', 
            'SZ' => 'Swaziland',  
            'SE' => 'Sweden', 
            'CH' => 'Switzerland',  
            'SY' => 'Syrian Arab Republic', 
            
            'TJ' => 'Tajikistan', 
            'TZ' => 'Tanzania, United Republic of', 
            
            'TG' => 'Togo', 
            'TK' => 'Tokelau', 
            'TO' => 'Tonga',  
            'TT' => 'Trinidad and Tobago',  
            'TN' => 'Tunisia',  
            'TR' => 'Turkey', 
            'TM' => 'Turkmenistan', 
            'TC' => 'Turks and Caicos Islands', 
            'TV' => 'Tuvalu', 
            'UG' => 'Uganda', 
            'UA' => 'Ukraine', 
            'AE' => 'United Arab Emirates', 
            'GB' => 'United Kingdom', 
            'US' => 'United States', 
            'UM' => 'United States Minor Outlying Islands', 
            'UY' => 'Uruguay',  
            'UZ' => 'Uzbekistan', 
            'VU' => 'Vanuatu',  
            'VE' => 'Venezuela', 
            'VN' => 'Viet Nam', 
            'VG' => 'Virgin Islands (British)', 
            'VI' => 'Virgin Islands (U.S.)',  
            'WF' => 'Wallis and Futuna Islands',  
            'EH' => 'Western Sahara', 
            'YE' => 'Yemen',  
            'YU' => 'Yugoslavia', 
            'ZM' => 'Zambia', 
            'ZW' => 'Zimbabwe'             
            );
    }

    public static function getChineseZodiac($id = null)
    {
        $res = array('' => 'All') + self::getChineseZodiacPostAd();
        
        if ($id !== null && !empty($res[$id])) {
            return $res[$id];
        }
        return $res;
    }

    public static function getChineseZodiacPostAd()
    {
        $view = Zend_Registry::get('Zend_View');
        return array(
            '' => 'Select',
            1 => 'Rat',
            2 => 'Ox',
            3 => 'Tiger',
            4 => 'Rabbit',
            5 => 'Dragon',
            6 => 'Snake',
            7 => 'Horse',
            8 => 'Pig',
            9 => 'Monkey',
            10 => 'Rooster',
            11 => 'Dog',
            12 => 'Sheep'
        );
    }

    public static function getHoroscope($id = null)
    {
        $res = array('' => 'All') + self::getHoroscopePostAd();
        
        if ($id !== null && !empty($res[$id])) {
            return $res[$id];
        }
        return $res;
    }

    public static function getHoroscopePostAd()
    {
        return array(
            '' => 'Select',
            1 => 'Aries',
            2 => 'Taurus',
            3 => 'Gemini',
            4 => 'Cancer',
            5 => 'Leo',
            6 => 'Virgo',
            7 => 'Libra',
            8 => 'Scorpio',
            9 => 'Sagittarius',
            10 => 'Capricorn',
            11 => 'Aquarius',
            12 => 'Pisces'
        );
    }
    

    
    public static function getSearchTextTerms() 
    {
        return array(
            'description'            => '1.0', 
            'title'                  => '7.0', 
            'area_l2_name'          => '9.0',
            'street'                 => '7.0',
            'education_name'         => '5.0', 
            'languages_name'         => '5.0',
            'nationality_name'       => '5.0',
            'maritalstatus_name'     => '5.0',
            'gender_name'            => '5.0',
            'visastatus_name'        => '5.0',
            'householdcleaning_name' => '5.0',
        );
    }
    
    
    /*
     * return a list of all the possible values that should be extracted from the keyword search and be specified as exact term
     * 
     */
    public static function getExactSeachTerms() 
    {
       return array(
                'education_name'         => self::getEducation(),
                'languages_name'         => self::getLanguages(),
                'nationality_name'       => self::getNationality(),
                'maritalstatus_name'     => self::getMaritalStatus(),
                'gender_name'            => self::getGender(),
                'visastatus_name'        => self::getVisastatus(),
                'householdcleaning_name' => self::getHouseholdCleaning()
           );
    }    
    
    public function getSolrDocument($document = null)
    {
        if (!$document instanceof Apache_Solr_Document) {
            $document = new Apache_Solr_Document();
        }
        $view = Zend_Registry::get('Zend_View');
        
        //Maids
        $document->dateofbirth = gmdate ('Y-m-d\TH:i:s\Z', strtotime($this->dob));
        
        if (!empty($this->ed)) {
            foreach ((array)$this->ed as $data) {
                $document->addField('education', (string)$data);
                $document->addField('education_name', self::getEducation($data));
                $document->addField('education_name',  $view->t(self::getEducation($data), Model_Translate::TC));
            }
        }        

        if (!empty($this->languages)) {
            foreach ((array)$this->languages as $data) {
                $document->addField('languages', (string)$data);
                $document->addField('languages_name', self::getLanguages($data));
                $document->addField('languages_name',  $view->t(self::getLanguages($data), Model_Translate::TC));
            }
        }        

        if (!empty($this->na)) {
            foreach ((array)$this->na as $data) {
                $document->nationality = (string)$data;
                $document->addField('nationality_name', self::getNationality($data));
                $document->addField('nationality_name',  $view->t(self::getNationality($data), Model_Translate::TC));
            }
        }        

        if (!empty($this->re)) {
            foreach ((array)$this->re as $data) {
                $document->religion =  (string)$data;
                $document->addField('religion_name', self::getReligion($data));
                $document->addField('religion_name',  $view->t(self::getReligion($data), Model_Translate::TC));
            }
        }        

        if (!empty($this->ms)) {
            foreach ((array)$this->ms as $data) {
                $document->maritalstatus = (string)$data;
                $document->addField('maritalstatus_name', self::getMaritalStatus($data));
                $document->addField('maritalstatus_name',  $view->t(self::getMaritalStatus($data), Model_Translate::TC));
            }
        }        

        if (!empty($this->ge)) {
            foreach ((array)$this->ge as $data) {
                $document->gender = (string)$data;
                $document->addField('gender_name', self::getGender($data));
                $document->addField('gender_name',  $view->t(self::getGender($data), Model_Translate::TC));
            }
        }            

        $document->availabletostart             = (string)$this->as;
        $document->employmenttype               = (int)$this->et;
        $document->visastatus                   = (int)$this->vs;
        $document->reasonleavingpreviousjob     = (string)$this->rlj;
        $document->specialities                 = (string)$this->spo;
        $document->yearsexperiencenewborn       = (int)$this->yen;
        $document->yearsexperiencechildren      = (int)$this->yec;
        $document->yearsexperiencedisable       = (int)$this->yed;
        $document->yearsexperienceelderly       = (int)$this->yee;
        $document->salary                       = (int)$this->salary;
        $document->salary_hour                  = (int)$this->salary_hour;
        
		if (!empty($this->cn)) {
			$document->addField('contact_number', (string)$this->cn);
		}
		
        if (!empty($this->hc)) {
            foreach ((array)$this->hc as $data) {
                $document->addField('householdcleaning', (string)$data);
                $document->addField('householdcleaning_name', self::getHouseholdCleaning($data));
                $document->addField('householdcleaning_name',  $view->t(self::getHouseholdCleaning($data), Model_Translate::TC));
            }
        }        /*
        $document->hongkongyearsexperience      = (int)$this->hkye;
        $document->indonesiayearsexperience     = (int)$this->inye;
        $document->malaysiayearsexperience      = (int)$this->maye;
        $document->middleeastyearsexperience    = (int)$this->miye;
        $document->philippinesyearsexperience   = (int)$this->phye;
        $document->singaporeyearsexperience     = (int)$this->siye;
        $document->taiwanyearsexperience        = (int)$this->taye;
        $document->thailandyearsexperience      = (int)$this->thye;
        $document->chinayearsexperience         = (int)$this->chye;
        $document->otheryearsexperience         = (int)$this->otye;
         * */
        $document->weight                       = (int)$this->we;
        $document->height                       = (int)$this->he;
        $document->preferredjoblocation         = (int)$this->pjl;
 
        return parent::getSolrDocument($document);
    }
    
    public static function getSearchResultSort()
    {
        return array(
            'recent'  => 'Most Recent',
            'rel'     => 'Relevance',
        );
    }        
    
    public function checkPerTypeDataSanity()
    {
    	$count = 0;
    	$missing = array();
    	$to_save = array();
    	//echo "adasda";exit();
    	//call the checker for basic info
    	$arr = parent::checkPerTypeDataSanity();    	//$this->checkCommonDataSanity(); 
		if(!empty($arr)){   
			//merge missings	
	    	$missing = array_merge($missing, $arr['errors']);
	    	
			//use parent's count
	    	$count = $arr['error_count'];
    	}
    	
		//dateofbirth
        if(empty($this->dob)){
			$count++;
			$missing['dateofbirth'][] = 'dateofbirth cannot be empty';
		}
		//education
		if(empty($this->ed)){
			$count++;
			$missing['education'][] = 'education cannot be empty';
		}else{
	        if(!array_key_exists($this->ed, $this->getEducationPostAd())){
				$count++;
				$missing['education'][] = 'education value not existing (ed: '.$this->ed.')';
			}
		}
		//languages
		if(empty($this->lag)){
			$count++;
			$missing['languages'][] = 'languages cannot be empty';
		}else{
	        if(!is_array($this->lag)){
				$count++;
				$missing['languages'][] = "value is not an array";//'languages value not existing (lag: '.$this->lag.')';
			}
		}
        
		//nationality
		if(empty($this->na)){
			$count++;
			$missing['nationality'][] = 'nationality cannot be empty';
		}else{
	       	if(!array_key_exists($this->na, $this->getNationalityPostAd())){
				$count++;
				$missing['nationality'][] = 'nationality value not existing (na: '.$this->na.')';
			}
		}
        
		//religion
		if(empty($this->re)){
			$count++;
			$missing['religion'][] = 'religion cannot be empty';
		}else{
	        if(!array_key_exists($this->re, $this->getReligionPostAd())){
				$count++;
				$missing['religion'][] = 'religion value not existing (re: '.$this->re.')';
			}
		}
        
		//maritalstatus
		if(empty($this->ms)){
			$count++;
			$missing['maritalstatus'][] = 'maritalstatus cannot be empty';
		}else{
	        if(!array_key_exists($this->ms, $this->getMaritalStatusPostAd())){
				$count++;
				$missing['maritalstatus'][] = 'maritalstatus value not existing (ms: '.$this->ms.')';
			}
		}
        
		//gender
		if(empty($this->ge)){
			$count++;
			$missing['gender'][] = 'gender cannot be empty';
		}else{
	        if(!array_key_exists($this->ge, $this->getGender())){
				$count++;
				$missing['gender'][] = 'gender value not existing (ge: '.$this->ge.')';
			}
		}
        
		//availabletostart
        if(empty($this->as)){
			$count++;
			$missing['availabletostart'][] = 'availabletostart cannot be empty';
		}
		
		//employmenttype
		if(empty($this->et)){
			$count++;
			$missing['employmenttype'][] = 'employmenttype cannot be empty';
		}else{
	        if(!is_array($this->et)){
				$count++;
				$missing['employmenttype'][] = "value is not an array";//'employmenttype value not existing (et: '.$this->et.')';
			}
		}
        
		//visastatus
        if(!empty($this->vs) && !array_key_exists($this->vs, $this->getVisastatusPostAd())){
			$count++;
			$missing['visastatus'][] = 'visastatus value not existing (vs: '.$this->vs.')';
		}
		
		//reasonleavingpreviousjob
        if(empty($this->rlj)){
			$count++;
			$missing['reasonleavingpreviousjob'][] = 'reasonleavingpreviousjob cannot be empty';
		}
		
		//contact_number
        if(empty($this->cn)){
			$count++;
			$missing['contact_number'][] = 'contact_number cannot be empty';
		}
		
		//skilllevelwestern
		if(empty($this->slw)){
			$count++;
			$missing['skilllevelwestern'][] = 'skilllevelwestern cannot be empty';
		}else{
	        if(!array_key_exists($this->slw, $this->getSkillLevelPostAd())){
				$count++;
				$missing['skilllevelwestern'][] = 'skilllevelwestern value not existing (slw: '.$this->slw.')';
			}
		}
        
		//skilllevelchinese
		if(empty($this->slc)){
			$count++;
			$missing['skilllevelchinese'][] = 'skilllevelchinese cannot be empty';
		}else{
	        if(!array_key_exists($this->slc, $this->getSkillLevelPostAd())){
				$count++;
				$missing['skilllevelchinese'][] = 'skilllevelchinese value not existing (slc: '.$this->slc.')';
			}
		}
        
		//specialities
        if(empty($this->spo)){
			$count++;
			$missing['specialities'][] = 'specialities cannot be empty';
		}
		//yearsexperiencenewborn
		if(empty($this->yen)){
			$count++;
			$missing['yearsexperiencenewborn'][] = 'yearsexperiencenewborn cannot be empty';
		}else{
		    if(!array_key_exists($this->yen, $this->getYearExperiencePostAd())){
				$count++;
				$missing['yearsexperiencenewborn'][] = 'yearsexperiencenewborn value not existing (yen: '.$this->yen.')';
			}
		}
        
		//yearsexperiencechildren
		if(empty($this->yec)){
			$count++;
			$missing['yearsexperiencechildren'][] = 'yearsexperiencechildren cannot be empty';
		}else{
	        if(!array_key_exists($this->yec, $this->getYearExperiencePostAd())){
				$count++;
				$missing['yearsexperiencechildren'][] = 'yearsexperiencechildren value not existing (yec: '.$this->yec.')';
			}
		}
        
		//yearsexperiencedisable
		if(empty($this->yed)){
			$count++;
			$missing['yearsexperiencedisable'][] = 'yearsexperiencedisable cannot be empty';
		}else{
	        if(!array_key_exists($this->yed, $this->getYearExperiencePostAd())){
				$count++;
				$missing['yearsexperiencedisable'][] = 'yearsexperiencedisable value not existing (yed: '.$this->yed.')';
			}
		}
        
		//yearsexperienceelderly
		if(empty($this->yee)){
			$count++;
			$missing['yearsexperienceelderly'][] = 'yearsexperienceelderly cannot be empty';
		}else{
	        if(!array_key_exists($this->yee, $this->getYearExperiencePostAd())){
				$count++;
				$missing['yearsexperienceelderly'][] = 'yearsexperienceelderly value not existing (yee: '.$this->yee.')';
			}
		}
        
		//householdcleaning
        if(!empty($this->hc) && !is_array($this->hc)){
			$count++;
			$missing['householdcleaning'][] = 'householdcleaning value not existing (hc: '.$this->hc.')';
		}
		
		if (!empty($missing)) {
	        $to_save['ls'] = $this->_id;
	        $to_save['errors'] = $missing;
	        $to_save['error_count'] = $count;
	    }
        return $to_save;       
    }

    public function exportRest($compressed = false)
    {
        $res = parent::exportRest($compressed);
        $view = Zend_Registry::get('Zend_View');

        $res['type'] = 'dh';
        if ($compressed) {
            return $res;
        }
        

        $res['dob'] = !empty($this->dob) ? (string)date('Y-m-d', $this->dob->sec) : '';
        $res['salary_month'] = !empty($this->salary) ? (string)$this->salary : '';
        $res['salary_hour'] = !empty($this->salaray_hour) ? (string)$this->salary_hour : '';
        if (!empty($this->ed)) {
            foreach ((array)$this->ed as $data) {
                $res['education'] =  (string)$data;
                $res['education_en'] = self::getEducation($data);
                $res['education_tc'] =  $view->t(self::getEducation($data), Model_Translate::TC);
            }
        } 
        if (!empty($this->languages)) {
            foreach ((array)$this->languages as $data) {
                $res['languages'] = (string)$data;
                $res['languages_en'] =  self::getLanguages($data);
                $res['languages_tc'] =   $view->t(self::getLanguages($data), Model_Translate::TC);
            }
        }  
        if (!empty($this->na)) {
            foreach ((array)$this->na as $data) {
                $res['nationality'] = (string)$data;
                $res['nationality_en'] = self::getNationality($data);
                $res['nationality_tc'] =  $view->t(self::getNationality($data), Model_Translate::TC);
            }
        }        

        if (!empty($this->re)) {
            foreach ((array)$this->re as $data) {
                $res['religion'] = (string)$data;
                $res['religion_en'] = self::getReligion($data);
                $res['religion_tc'] =  $view->t(self::getReligion($data), Model_Translate::TC);
            }
        }        

        if (!empty($this->ms)) {
            foreach ((array)$this->ms as $data) {
                $res['maritalstatus'] = (string)$data;
                $res['maritalstatus_en'] = self::getMaritalStatus($data);
                $res['maritalstatus_tc'] =  $view->t(self::getMaritalStatus($data), Model_Translate::TC);
            }
        }        

        if (!empty($this->ge)) {
            foreach ((array)$this->ge as $data) {
                $res['gender'] = (string)$data;
                $res['gender_en'] = self::getGender($data);
                $res['gender_tc'] =  $view->t(self::getGender($data), Model_Translate::TC);
            }
        }            

        if(!empty($this->street)) {
            unset($res['street']);
        }
        if(!empty($this->longitude)) {
            unset($res['longitude']);
        }
        if(!empty($this->latitude)) {
            unset($res['latitude']);
        }

        unset($res['price']);
        return $res;
    }


    public function processRestForm()
    {
        $post = $_POST;

        //Date of birth        
        if (empty($_POST['dob'])) {
            throw new Ac_Exception_MissingInformation('Invalid value for date of birth');
        }        
        $tmp = strtotime($_POST['dob']);
        if (!checkdate(date('m', $tmp), date('d', $tmp), date('Y', $tmp))) {
            throw new Ac_Exception_MissingInformation('Invalid value for date of birth');
        }        
        if (!empty($_POST['dob'])) {
            $this->dateofbirth = new MongoDate(strtotime($_POST['dob']));
        }
       
        //Education
        if (!empty($_POST['education']) && !is_string(self::getEducation($_POST['education'])) ) {
            throw new Ac_Exception_MissingInformation('Invalid value for education');
        }         
        if (!empty($_POST['education'])) {
            $this->education = intval($_POST['education']);
        }

        //Languages
        if (empty($_POST['languages'])) {
            //throw new Ac_Exception_MissingInformation('Invalid value for languages');
            $_POST['languages'] = array();
        }
        foreach($_POST['languages'] as $lang) {
            if(!is_string(self::getLanguages($lang))) {
                throw new Ac_Exception_MissingInformation('Invalid value for languages');
            }
            if (!empty($_POST['languages'])) {
                $this->languages = $_POST['languages'];
            }
        }

        //Marital status
        if (empty($_POST['marital']) || !is_string(self::getMaritalStatus($_POST['marital'])) ) {
            throw new Ac_Exception_MissingInformation('Invalid value for marital status');
        }
        if (!empty($_POST['marital'])) {
            $this->maritalstatus = intval($_POST['marital']);
        }

        //Contact number
        /*
        if (empty($_POST['contact'])) {
            throw new Ac_Exception_MissingInformation('Invalid value for contact number');
        } 
        */       
        if (!empty($_POST['contact'])) {
            $this->contact_number = (string)$_POST['contact'];
        }

        //Gender
        if (empty($_POST['gender']) || !is_string(self::getGender($_POST['gender'])) ) {
            throw new Ac_Exception_MissingInformation('Invalid value for gender');
        }
        if (!empty($_POST['gender'])) {
            $this->gender = intval($_POST['gender']);
        }

        //Nationality
        if (empty($_POST['nationality']) || !is_string(self::getNationality(strtoupper($_POST['nationality'])))) {
            throw new Ac_Exception_MissingInformation('Invalid value for nationality');
        }  
        if (!empty($_POST['nationality'])) {
            $this->nationality = array($_POST['nationality']);
        }



        //parent::processRestForm();
        return true;
    }
}
